package sunwin.yoms.service.publicty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.dao.NewsTypeDao;
import sunwin.yoms.domain.publicty.NewsTypeDomain;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by watson on 2015/7/28.
 */
@Service
public class NewsTypeService {
    @Autowired
    private NewsTypeDao newsTypeDao;

    //查询
    public List<NewsTypeDomain> getNewsType(NewsTypeDomain newsTypeDomain) {
        List<NewsTypeDomain> newsTypeDomains = new ArrayList<NewsTypeDomain>();
        newsTypeDomains = newsTypeDao.getDomainCollection(newsTypeDomain);
        return newsTypeDomains;
    }

    //id查询
    public NewsTypeDomain getNewsDomainById(int newsTypeId) {
        return newsTypeDao.getDomainById(newsTypeId);
    }

    //增加
    public void addNewsTypeDomain(NewsTypeDomain newsTypeDomain) throws YomsException {
        if (newsTypeDao.addDomain(newsTypeDomain) != 1) {
            throw new YomsException("增加新闻类型失败");
        }
    }

    //删除
    public void deleteNewsTypeDomain(NewsTypeDomain newsTypeDomain) throws YomsException {
        if (newsTypeDao.deleteDomain(newsTypeDomain) != 1) {
            throw new YomsException("删除新闻类型失败");
        }
    }

    //更新
    public void upNewsTypeDomain(NewsTypeDomain newsTypeDomain) throws YomsException {
        if (newsTypeDao.updateDomain(newsTypeDomain) != 1) {
            throw new YomsException("更新新闻类型失败");
        }

    }

    //总数量
    public int getCountDomain() {
        return newsTypeDao.getDomainCount();
    }


}
